from utils import *
# 读取txt文件中的值，一样一样读取，列分别为：类别，x_center,y_center,w,h,并且都是小数，因此需要乘对应宽高

height,width=get_img_hw("src/1.jpg")
with open("src/1.txt","r")as f:
    txt_all_data=f.readlines()
with open("src/classes.txt","r")as f:
    txt_all_cata_str=f.read()

txt_all_cata=txt_all_cata_str.split("\n")[:-1]#['eyes', 'mouse']
names=[]
for i in range(len(txt_all_data)):
    temp_data=txt_all_data[i].split(" ")
    names.append(temp_data[0])
    temp_data[4]=temp_data[4][:-1]
    txt_all_data[i]={txt_all_cata[int(names[i])]:[
        int(float(temp_data[1])*width)-int((float(temp_data[3])*width)/2),
        int(float(temp_data[2])*height)-int((float(temp_data[4])*height)/2),
        int(float(temp_data[1])*width)+int((float(temp_data[3])*width)/2),
        int(float(temp_data[2])*height)+int((float(temp_data[4])*height)/2),
    ]}
# print(txt_all_data)# [{'eyes': [106, 156, 238, 184]}, {'mouse': [138, 230, 202, 268]}, {'eyes': [557, 145, 645, 173]}, {'mouse': [593, 216, 631, 252]}, {'eyes': [783, 152, 811, 178]}, {'mouse': [771, 218, 799, 254]}]



p_list=[]
for i in txt_all_data:
    p_list.append(list(i.values())[0])
show_with_rs("src/1.jpg",p_list)
